//
//  ChatAvatarVeiw.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/5/25.
//

import SwiftUI
import Kingfisher

struct ChatAvatarVeiw: View {
    @State var item: ChatBean

    var body: some View {
        if item.role?.avatar?.isEmpty == false {
            KFImage(URL(string: item.role?.avatar.formatCdn() ?? ""))
                .resizable()
                .placeholder{
                    Image(.appDefaultLogo)
                        .resizable()
                        .scaledToFill()
                        .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
                        .frame(width: 40,height: 40)
                        .background(Color.hex("515151").opacity(0.1))
                        .clipShape(Circle())
                }
                .background(Color.hex("515151").opacity(0.1))
                .scaledToFill()
                .frame(width: 40,height: 40)
                .clipShape(Circle())
        } else {
            Image(.appIconLogo)
                .resizable()
                .scaledToFill()
                .padding(EdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2))
                .frame(width: 40,height: 40)
                .background(Color.hex("515151").opacity(0.1))
                .clipShape(Circle())
        }
    }
}

#Preview {
    ChatAvatarVeiw(item: ChatBean())
}
